<template>
	<view class="wrapper">
		<view class="content">
			<form @submit="formLogin">
			<view class="inp-item">
				<view class="inp-text">原密码</view>
				<view class="input">
					<input type="password" placeholder="请输入原密码" name="password" placeholder-class="plass" />
				</view>
			</view>
			
			<view class="inp-item">
				<view class="inp-text">新密码</view>
				<view class="input">
					<input type="password" placeholder="请输入新密码" name="newpassword" placeholder-class="plass" />
				</view>
			</view>
			
			<view class="inp-item">
				<view class="inp-text">再次输入</view>
				<view class="input">
					<input placeholder="请输入再次输入新密码" name="oncenewpassword" placeholder-class="plass" />
				</view>
			</view>
			
			
			<button class="confirm-btn" formType="submit" >修改</button>
			</form>
		</view>
		
	</view>
</template>

<script>
	var  graceChecker = require("../../common/graceChecker.js");
	export default {
		data() {
			return {
			
			}
		},
		onLoad() {
		
		},
		methods: {
			//修改账号密码登陆
			formLogin:function(e){
					var that = this;
					var data = e.detail.value;
					data.store_id = uni.getStorageSync('store_id');
					if(data.newpassword != data.oncenewpassword){
						that.$api.errorMsg('两次输入的密码不一致');return;
					}
					var rule = [
						{name:"password", checkType : "string", checkRule:"6,32",  errorMsg:"密码长度应为6~32位"},
						{name:"newpassword", checkType : "string", checkRule:"6,32",  errorMsg:"密码长度应为6~32位"},
						{name:"oncenewpassword", checkType : "string", checkRule:"6,32",  errorMsg:"密码长度应为6~32位"}
					];
					var checkRes = graceChecker.check(data,rule);
					if(checkRes){
						that.$api.WaitModel('正在提交...');
						uni.request({
							url: that.$websiteUrl + '/index.php/Store/User/changepwd.html', 
							data: data,
							method:'POST',
							dataType:'json',
							header: {'content-type' : 'application/x-www-form-urlencoded'},
							success: (resa) => {
								var one = resa.data;
								that.$api.HideWaitModel();
								if(one.status==200){
									that.$api.successMsg(one.message);
									setTimeout(function () {
										uni.getStorageSync('UserInfo','')
										uni.removeStorageSync('UserInfo');
											uni.redirectTo({
												url:'./logIn'
											})
									}, 2000);
								}else{
									that.$api.errorMsg(one.message);
								}
							},
							fail: (resa) => {
								that.$api.HideWaitModel();
								that.$api.errorMsg('网络连接超时，请检查您的网络');
							}
						})
					}else{
						that.$api.errorMsg(graceChecker.error);
						setTimeout(function () {
							this.loadinga = false;
						}, 2000);
					}
				
			},

		}
	}
</script>

<style lang="scss">
	.content {
		padding: 45upx 30upx 30upx;
	}
	
	.inp-item {
		padding: 15upx 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		line-height: 75upx;
		// border-bottom: 1upx solid #eee;
		.inp-text {
			font-size: 28upx;
			color: #333;
		}
		.input {
			width: 490upx;
			height: 75upx;
			border-bottom: 1upx solid #eee;
			input {
				width: 100%;
				height: 100%;
				font-size: 28upx;
				color: #333;
			}
			.plass {
				font-size: 28upx;
				color: #ccc;
			}
		}
	}
	
	.confirm-btn {
		margin: 125upx auto 0;
		width: 560upx;
		height: 70upx;
		background: #f70000;
		border-radius: 40upx;
		font-size: 28upx;
		text-align: center;
		line-height: 70upx;
		letter-spacing: 1px;
		color: #fff;
	}
	
</style>
